﻿using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using Remindme.Model;
using Remindme.Repository.Interfaces;
using Remindme.Services.Interfaces;
using Remindme.ViewModel.Interfaces;
using System;

namespace Remindme.ViewModel
{
    public class DetailViewModel : ViewModelBase, IDetailViewModel, INavigable
    {
        private readonly INavigationService _navigationService;
        private readonly IItemRepository _itemRepository;
        private readonly IArticleRepository _articleRepository;

        public object NavigationContext
        {
            set
            {
                if (value == null)
                    return;
                if (value is ItemModel)
                {
                    if (value != Item)
                        Item = value as ItemModel;
                }
                if (value is ArticleModel)
                {
                    if (value != Article)
                        Article = value as ArticleModel;
                }
            }
        }

        /// <summary>
        /// The <see cref="Item" /> property's name.
        /// </summary>
        public const string ItemPropertyName = "Item";

        private ItemModel _item = null;

        /// <summary>
        /// Sets and gets the Item property.
        /// Changes to that property's value raise the PropertyChanged event. 
        /// </summary>
        public ItemModel Item
        {
            get
            {
                return _item;
            }

            set
            {
                if (_item == value)
                {
                    return;
                }

                RaisePropertyChanging(ItemPropertyName);
                _item = value;
                RaisePropertyChanged(ItemPropertyName);
            }
        }


        /// <summary>
        /// The <see cref="Article" /> property's name.
        /// </summary>
        public const string ArticlePropertyName = "Article";

        private ArticleModel _article = null;

        /// <summary>
        /// Sets and gets the Article property.
        /// Changes to that property's value raise the PropertyChanged event. 
        /// </summary>
        public ArticleModel Article
        {
            get
            {
                return _article;
            }

            set
            {
                if (_article == value)
                {
                    return;
                }

                RaisePropertyChanging(ArticlePropertyName);
                _article = value;
                RaisePropertyChanged(ArticlePropertyName);
            }
        }

        public RelayCommand<ItemModel> MarkAsReadCommand { get; private set; }
        public RelayCommand<ItemModel> ArchiveCommand { get; private set; }
        public RelayCommand<ItemModel> DeleteCommand { get; private set; }

        public DetailViewModel(
            INavigationService navigationService,
            IItemRepository itemRepository)
        {
            this._navigationService = navigationService;
            this._itemRepository = itemRepository;

            this.MarkAsReadCommand = new RelayCommand<ItemModel>(this.MarkAsReadAsync);
            this.ArchiveCommand = new RelayCommand<ItemModel>(this.ArchiveAsync);
            this.DeleteCommand = new RelayCommand<ItemModel>(this.DeleteAsync);
        }

        async void MarkAsReadAsync(ItemModel item)
        { 
            throw new NotImplementedException();
        }

        async void ArchiveAsync(ItemModel item)
        { 
            throw new NotImplementedException();
        }

        async void DeleteAsync(ItemModel item)
        { 
            throw new NotImplementedException();
        }
    }
}
